<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        #box{
            width: 200px;
            height: 50px;
            font-size: 30px;
            border:1px solid #ddd;
        }
    </style>
</head>
<body>
    数字1：<input type="text" id="num1">
    数字2：<input type="text" id="num2">

    <br>

    <button onclick="add()">＋</button>

    <hr>

    <div id="box"></div>

    <script>
        function add(){
            var num1 = document.getElementById('num1');
            var num2 = document.getElementById('num2');

            var xhr = new XMLHttpRequest();
            // 事件回调
            xhr.onreadystatechange = function(){
                if(xhr.readyStatus == 4){
                    if(xhr.status == 200){
                        //获取响应文本
                        box.innerHTML = xhr.responseText; 
                    }
                }
            }

            //请求初始化
            xhr.open('get', './php/2.php?a='+num1+'&b='+num2,true);

            //正式发送
            xhr.seng();
        }


    </script>


</body>
</html>